{% extends 'layout.html' %}
{% load static %}

{% block content %}
    <div class="container">
        <div class="row">
            <div class="col-xs-6" style="height:400px;">
                <!-- 为 ECharts 准备一个定义了宽高的 DOM -->
                <div id="m1" style="height:400px;"></div>
            </div>
            <div class="col-xs-6" style="height:400px">
                <div id="m2" style="height:400px;"></div>
            </div>
        </div>
        <div class="row">
            <div class="col-xs-12">
                <div id="m3" style="height:500px;"></div>
            </div>
        </div>
    </div>
{% endblock %}

{% block js %}
    <!-- 引入刚下载的 ECharts 文件 -->
    <script src="{% static 'js/echarts.js' %}"></script>
    <script type="text/javascript">
        $(function () {
            Charoptin();
            Piechar();
            Linechar();
        })

        function Charoptin() {
            // 基于准备好的dom，初始化echarts实例
            var myChart = echarts.init(document.getElementById('m1'));
            // 指定图表的配置项和数据
            var option = {
                title: {
                    text: '销量柱状图',
                    left: "center",

                },
                tooltip: {},
                legend: {
                    data: [],
                    bottom: 0,
                },
                xAxis: {
                    data: []
                },
                yAxis: {},
                series: []
            };
            //ajax请求后台提供数据
            $.ajax({
                url: '/data/char/',
                type: "get",
                dataType: "JSON",
                success: function (res) {
                    if (res.status) {
                        console.log(res.data.series_data);
                        option.legend.data = res.data.legend_data;
                        option.series = res.data.series_data;
                        option.xAxis.data = res.data.xAxis_data;
                        // 使用刚指定的配置项和数据显示图表。
                        myChart.setOption(option);
                    }
                }
            });

        }

        function Piechar() {
            // 基于准备好的dom，初始化echarts实例
            var myChart = echarts.init(document.getElementById('m2'));
            // 指定图表的配置项和数据
            var option = {
                title: {
                    text: '员工分布',
                    left: 'center'
                },
                tooltip: {
                    trigger: 'item'
                },
                legend: {
                    bottom: 0
                },
                series: [
                    {
                        name: '员工',
                        type: 'pie',
                        radius: '50%',
                        data: [
                            {value: 1048, name: 'IT信息部'},
                            {value: 735, name: '财务部'},
                            {value: 580, name: '销售部'},
                        ],
                        emphasis: {
                            itemStyle: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            };
            myChart.setOption(option);
        }

        function Linechar() {
            // 基于准备好的dom，初始化echarts实例
            var myChart = echarts.init(document.getElementById('m3'));
            var option = {
                title: {
                    text: 'Stacked Line',
                },
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    data: ['Email', 'Union Ads', 'Video Ads', 'Direct', 'Search Engine'],
                    bottom:0
                },
                toolbox: {
                    feature: {
                        saveAsImage: {}
                    }
                },
                xAxis: {
                    type: 'category',
                    boundaryGap: false,
                    data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
                },
                yAxis: {
                    type: 'value'
                },
                series: [
                    {
                        name: 'Email',
                        type: 'line',
                        stack: 'Total',
                        data: [120, 132, 101, 134, 90, 230, 210]
                    },
                    {
                        name: 'Union Ads',
                        type: 'line',
                        stack: 'Total',
                        data: [220, 182, 191, 234, 290, 330, 310]
                    },
                    {
                        name: 'Video Ads',
                        type: 'line',
                        stack: 'Total',
                        data: [150, 232, 201, 154, 190, 330, 410]
                    },
                    {
                        name: 'Direct',
                        type: 'line',
                        stack: 'Total',
                        data: [320, 332, 301, 334, 390, 330, 320]
                    },
                    {
                        name: 'Search Engine',
                        type: 'line',
                        stack: 'Total',
                        data: [820, 932, 901, 934, 1290, 1330, 1320]
                    }
                ]
            };
            myChart.setOption(option);
        }
    </script>
{% endblock %}